package com.copa.ums.modules.ums.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.copa.ums.common.vo.ResponseVo;
import com.copa.ums.modules.ums.model.UmsResourceCategory;
import com.copa.ums.modules.ums.mapper.UmsResourceCategoryMapper;
import com.copa.ums.modules.ums.service.UmsResourceCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author copa
 * @since 2022-10-31
 */
@Service
public class UmsResourceCategoryServiceImpl extends ServiceImpl<UmsResourceCategoryMapper, UmsResourceCategory> implements UmsResourceCategoryService {

    @Override
    public ResponseVo<List<UmsResourceCategory>> listAll() {
        QueryWrapper<UmsResourceCategory> wrapper = new QueryWrapper<>();
        wrapper.lambda().orderByDesc(UmsResourceCategory::getSort);
        return ResponseVo.success(list(wrapper));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseVo<String> create(UmsResourceCategory umsResourceCategory) {
        //umsResourceCategory.setCreateTime(new Date());
        return save(umsResourceCategory)
                ? ResponseVo.success(null)
                : ResponseVo.failed();
    }
}
